<template>
	<div class="gn_companymesg">
		<div class="company_details">
			<div class="mesg_tit">
				机构信息
			</div>
			<div v-loading="loading">
				<div class="company_mesg clearfix" >
					<div class="company_list fl clearfix" >
						<span class="company_listtit fl">公司全称：</span>
						<div class="company_listinput" >
							{{name}}
						</div>
					</div>

					<div class="company_list fl clearfix">
						<span class="company_listtit fl">公司简称：</span>
						<div class="company_listinput">
							{{sname}}
						</div>
					</div>

					<div class="company_list company100 clearfix">
						<span class="company_listtit fl">公司地址：</span>
						<div class="company_listinput">
							{{address}}
						</div>
					</div>
				</div>
				<!-- <div class="company_details">
					<p class="mesg_tit">登录账户</p>
					<div class="company_mesg clearfix" >
						<div class="company_list fl clearfix">
							<span class="company_listtit fl">登录账户：</span>
							<div class="company_listinput">
								
								<div class="poptext">{{account}}</div>
								<el-button class="company_editbtn" type="text" @click="editpassword">修改密码</el-button>
							</div>
						</div>
					</div>
				</div> -->

				<!-- <div class="company_details">
					<p class="mesg_tit">业务信息</p>
					<div class="company_mesg clearfix" >
						<div class="company_list fl clearfix">
							<span class="company_listtit fl">坐席数量：</span>
							<div class="company_listinput">
								<p class="company_inpmesg mr5" >{{phoneNum}}</p>
								<a class="company_phonetips">坐席客服不够用？快联系我们   <span class="company_callnum">{{phonenumber}}</span></a>
							</div>
						</div>
					</div>
				</div> -->
			</div>
			
		</div>

		
<!-- gm修改密码gm -->
    <el-dialog title="修改密码" 
							 :visible.sync="dialogFormVisible" 
							 center 
							 width="500px" 
							 :close-on-click-modal="false"
							 :show-close="false">
      <el-form :model="form" :rules="rulesPassword" ref="form" label-width="100px">
        <el-form-item label="原始密码">
          <el-input key="passwordtext" type="password" autocomplete="off" v-model="form.oldPassword" @blur="onBlur"></el-input>
        </el-form-item>
         <el-form-item label="新密码" prop="newPassword">
          <el-input  key="newpdtext" type="password" autocomplete="off" v-model="form.newPassword"></el-input>
        </el-form-item>
         <el-form-item label="重复密码" prop="aginNewPassword">
          <el-input key="agnewpdtext" type="password" autocomplete="off" v-model="form.aginNewPassword"></el-input>
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelBtn('form')">取 消</el-button>
        <el-button type="primary" @click="trueBtn('form')">确 定</el-button>
      </div>
    </el-dialog>
     <!-- gm修改密码gm -->

	</div>
</template>

<script>
import bus from '@/api/bus'
	import {getCompany,checkPassword,changePassword} from '@/api'
	export default{
		data(){
			const validatePassword = (rule, value, callback) => {
				// let reg = /[\w\d_]{6,16}/;
				let reg = /[\u4E00-\u9FA5A-Za-z0-9_]{6,16}/;
        if (value != '' && reg.test(value)) {
          callback()
        } else {
          callback(new Error('请正确输入密码'))
        }
      }
      const validateAginPassword = (rule, value, callback) => {
        if (value === this.form.newPassword) {
          callback()
        } else {
          callback(new Error('输入的密码和新设置的密码不一致'))
        }
      }
			return{
				roleId:'',
				name: '',
				sname: '',
				address: '',
				account:"",                     //登录账户
				phoneNum:"",                   //坐席数量
				phonenumber:"010-229283793",    //坐席客服备用电话
				dialogFormVisible: false,       //修改密码-弹出框 默认隐藏false，显示true 
				oldPassword: '',                //原始密码
        newPassword: '',                //新密码
        aginNewPassword: '',            //重复密码
				loading: true	,
				form: {
          oldPassword: '',
          newPassword: '',
          aginNewPassword: ''
        },
        rulesPassword: {
          newPassword: [{
            validator: validatePassword,
					  trigger: 'change'
          }],
          aginNewPassword:[{
            validator: validateAginPassword,
					  trigger: 'change'
          }]
        }
			}
		},
		created(){//加载查询
			this.getCompany()
			this.phoneNum = sessionStorage.getItem('phoneAmount')
		},
		methods:{
			getCompany(){
				getCompany().then(res => {        //调用查询接口
					let code = res.data.code
					if(code == 0) {
						let data= res.data.data;
						this.account = data.account     //登录账户
						this.name = data.name           //公司全称
						this.sname = data.sname         //公司简称
						this.address = data.address     //地址
						this.loading = false
					} else if (code == 1) {
						this.$message({
							message: res.data.msg
						})
					} 
				})
			},
			editpassword(){                       //修改密码按钮
				this.dialogFormVisible = true       //修改密码-弹出框 显示
				this.form.newPassword = ""               //原始密码
				this.form.aginNewPassword =""            //新密码
				this.form.oldPassword = ""               //重复密码
			},
			onBlur () {//原始密码 失去焦点
        let params = {
          password: this.form.oldPassword
        }
        checkPassword(params).then(res => {//调用验证密码接口
          let code = res.data.code
          if(code == 0) {
            this.$message({
              message: '输入正确'
            });
          } else if (code == 1) {
            this.form.oldPassword = ""
            this.$message({
							message: res.data.msg
            });
          }
        })
      },
      trueBtn (form) {//修改密码-确定
        this.$refs[form].validate((valid) => {//validate验证
          if (valid) {
            let params = {
              password: this.form.newPassword
            }
            changePassword(params).then(res => {//调用修改密码接口
              let code = res.data.code
              if (code == 0) {
                this.dialogFormVisible = false
                this.$message({
                  message: '密码修改成功'
                });
              } else if (code == 1) {
                this.$message({
                  message: res.data.msg
                })
              }
            })
          } else {
            //console.log('error submit!!');
					  return false;
          }
        })
        this.$refs[form].resetFields()
			},
      cancelBtn (formName) {
        this.dialogFormVisible = false	          //修改密码-弹出框隐藏
        this.$refs[formName].resetFields()
      }
    }
	};
</script>

<style scoped>

.company_listinput{display:flex;overflow:hidden;line-height:40px;}
.company_listinput .el-input{width:280px;}
.company_list{min-width:50%;margin-bottom:20px;}
.company_listtit{width:100px;line-height:40px;text-align:right;}
.company_editbtn{margin-left:5px;}
.company_phonetips{color:#de2b39;font-size:12px;line-height:40px;}
.company_inpmesg{line-height:40px;color:#333;}
.el-input__inner{color:#333;}
.company_callnum{color:#666;}
.company100{width:100%;clear:both;}
.company100 .el-input{width:60%;}
.edticompany_btn{float:right;}
.gn_companymesg{min-height: 450px}
</style>